package com.syzg.base.module.dao.impl;

import com.syzg.base.merge.model.Module;
import com.syzg.base.module.dao.ModuleDAO;
import com.syzg.common.dao.impl.BaseDAOHibernate;

import java.util.*;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

@Repository("moduleDAO")
public class ModuleDAOImpl extends BaseDAOHibernate<Module> implements ModuleDAO {

    public ModuleDAOImpl(){
    }

    protected Class<?> getEntityClass(){
        return Module.class;
    }

    /*@SuppressWarnings("unchecked")
	public List<Module> findModules(){
        String hql = "select a from Module as a where a.id <> 0 order by parentId,orderNo";
        List<Module> list = getHibernateTemplate().find(hql);
        return list; 
    }*/

    @SuppressWarnings("unchecked")
	public String getModuleNameByModuleCode(String moduleCode){
        String hql = "select a.name from Module as a where a.code=?";
        Query query = this.getSession().createQuery(hql);
        query.setParameter(0, moduleCode);
        List<String> list = query.list();
        String value = (String)list.get(0);
        return value;
    }

    @SuppressWarnings("unchecked")
	public String getModuleIdByModuleCode(String moduleCode){
        String hql = "select a.id from Module as a where a.code=:moduleCode";
        Query query = this.getSession().createQuery(hql);
        query.setParameter(0, moduleCode);
        List<String> list = query.list();
        String value = (String)list.get(0);
        return value;
    }
}